

/**
 * @file
 * @brief Defines the SocketCanClientRaw class which inherits CanClient.
 */

#pragma once

#include <unistd.h>

#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>

#include <linux/can.h>
#include <linux/can/raw.h>

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include "can_client.h"


namespace canbus
{
  // namespace can
  // {
    class SocketCanClientRaw //: public CanClient
    {
    public:
      bool Init(std::string port_);

      virtual ~SocketCanClientRaw();

      ErrorCode Start() ;
      void Stop() ;
      ErrorCode Send(canbus::CanFrame &frames, int32_t *const frame_num);
      // ErrorCode Send(const std::vector<canbus::CanFrame> &frames, int32_t *const frame_num);
      ErrorCode Receive(std::vector<canbus::CanFrame> *const frames, int32_t *const frame_num);
      std::string GetErrorString(const int32_t status);
      void RecvThreadFunc();
      void SendThreadFunc();

    private:
      int sock_can_fd = 0;
      std::string port_name; //dui ying can0 jiekou
      can_frame send_frames_[MAX_CAN_SEND_FRAME_LEN];
      can_frame recv_frames_[MAX_CAN_RECV_FRAME_LEN];
      struct sockaddr_can addr;
      struct ifreq ifr;

    protected:
      bool is_started_ = false;
    };
  // }
}